<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" >
      <el-table-column label="ID" prop="id" align="center">
        <template #default="{row}">
          <div>
            {{row.id || '--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="VIP卡名称" prop="vipName" align="center">
        <template #default="{row}">
          <div>
            {{row.vipName || '--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="VIP卡等级" prop="vipLevel" align="center">
        <template #default="{row}">
          <div>
            {{row.vipLevel || '--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="消耗几级飞机" prop="airLevel" align="center">
        <template #default="{row}">
          <div>
            {{row.airLevel || '--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="飞机数量" prop="airNumber" align="center">
        <template #default="{row}">
          <div>
            {{row.airNumber || '--'}}
          </div>
        </template>
      </el-table-column>

      <el-table-column label="奖励飞机等级" prop="rewardPlaneLevel" align="center">
      <template #default="{row}">
        <div>
          {{row.rewardPlaneLevel || '--'}}
        </div>
      </template>
      </el-table-column>
      <el-table-column label="奖励飞机体力状态" align="center" width="100" prop="rewardPlaneEnergy">
        <template #default="{row}">
          <div>
            {{row.rewardPlaneEnergy || '--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="激活所需能量值" align="center" width="100" prop="activationEnergy">
        <template #default="{row}">
          <div>
            {{row.activationEnergy || '--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="上线状态" align="center" width="100" prop="onlineStatus">
        <template #default="{row}">
          <div>
            <el-tag v-if="row.onlineStatus==1">关闭</el-tag>
            <el-tag v-else-if="row.onlineStatus==0" type="success">正常</el-tag>
            <div v-else>{{row.onlineStatus || '--'}}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" width="100" prop="type">
        <template #default="{row}">
          <div>
            <el-tag v-if="row.type==1">免广告</el-tag>
            <el-tag v-else-if="row.type==0" type="success">飞机卡</el-tag>
            <el-tag v-else-if="row.type==2" type="danger">高级卡</el-tag>
            <el-tag v-else-if="row.type==3" type="warning">飞机兑换的高级卡</el-tag>

          </div>
        </template>
      </el-table-column>

      <el-table-column label="天数" align="center" width="250" prop="day">
        <template #default="{row}">
          <div>{{row.day || '--'}}</div>
        </template>
      </el-table-column>
      <el-table-column label="高级卡产出收益" align="center" width="250" prop="outEnergy">
        <template #default="{row}">
          <div>{{row.outEnergy || '--'}}</div>
        </template>
      </el-table-column>
      <el-table-column label="说明" align="center" width="250" prop="details">
        <template #default="{row}">
          <div v-for="(item,index) in row.details" :key="index">
            {{item}}
          </div>
        </template>
      </el-table-column>

      <el-table-column label="备注" align="center" width="250" prop="description">
        <template #default="{row}">
          <div>
            {{row.description || '--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime"  width="160">
        <template #default="{row}">
          <span>{{ parseTime(row.createTime) || '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="220">
        <template #default="{row}">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(row)"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <add ref="addRef" @success="getList"/>
  </div>
</template>

<script>
import {mVipCardList, mVipCardRemove} from "@/api/aircraft/aircraft"
import add from "./components/add.vue"
export default {
  name: "Role",
  components: {
    add
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询角色列表 */
    async getList() {
      this.loading = true
      let res = await mVipCardList()
      this.roleList = res.data
      this.loading = false
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
     this.$refs.addRef.onOpen()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.addRef.onOpen(row)
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.id
      this.$modal.confirm('是否确认删除此会员？').then(function () {
        return mVipCardRemove({id:roleIds})
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {
      })
    },

  }
}
</script>
